package com.fjrz.bbxwj.mode.api

import com.fjrz.bbxwj.entity.*
import com.module.lemlin.mode.SubscribeListener
import com.module.lemlin.rxhttp.HttpServiceData
import com.module.lemlin.rxhttp.subscribe
import io.reactivex.rxjava3.disposables.Disposable
import rxhttp.RxHttp

/**
 * 消息中心（最新公告|最新系统消息|未读公告数|未读系统消息数）
 * */
fun messageInfo(
    listener: SubscribeListener<MessageInfoResponse>
): Disposable = subscribe(
    RxHttp.get("/api/message/info")
        .asClass(MessageInfoResponse::class.java)
    , listener
)

/**
 * 公告列表
 *
 * @param limit 条数
 * @param page 分页
 * */
fun messageAnnouncements(
    page: String, limit: String, listener: SubscribeListener<AnnouncementResponse>
): Disposable = subscribe(
    RxHttp.get("/api/message/announcements")
        .add("page", page)
        .add("limit", limit)
        .asClass(AnnouncementResponse::class.java)
    , listener
)

/**
 * 公告详情
 *
 * @param announcementId
 * */
fun messageAnnouncementsDetails(
    announcementId: String, listener: SubscribeListener<AnnouncementDetailsResponse>
): Disposable = subscribe(
    RxHttp.get("/api/message/announcement_detail")
        .add("announcement_id", announcementId)
        .asClass(AnnouncementDetailsResponse::class.java)
    , listener
)

/**
 * 公告已读
 *
 * @param act 1:单个已读2:全部已读
 * @param announcementId
 * */
fun messageAnnouncementsRead(
    act: String, announcementId: String, listener: SubscribeListener<HttpServiceData>
): Disposable = subscribe(
    RxHttp.get("/api/message/announcement_read")
        .add("act", act)
        .add("announcement_id", announcementId)
        .asClass(HttpServiceData::class.java)
    , listener
)

/**
 * 系统消息列表
 *
 * @param limit 条数
 * @param page 分页
 * */
fun messageSystem(
    page: String, limit: String, listener: SubscribeListener<MessageSystemResponse>
): Disposable = subscribe(
    RxHttp.get("/api/message/system_messages")
        .add("page", page)
        .add("limit", limit)
        .asClass(MessageSystemResponse::class.java)
    , listener
)

/**
 * 系统消息详情
 *
 * @param messageId
 * */
fun messageSystemDetails(
    messageId: String, listener: SubscribeListener<MessageSystemDetailsResponse>
): Disposable = subscribe(
    RxHttp.get("/api/message/system_message_detail")
        .add("message_id", messageId)
        .asClass(MessageSystemDetailsResponse::class.java)
    , listener
)

/**
 * 系统消息已读
 *
 * @param act 1:单个已读2:全部已读
 * @param messageId
 * */
fun messageSystemRead(
    act: String, messageId: String, listener: SubscribeListener<HttpServiceData>
): Disposable = subscribe(
    RxHttp.get("/api/message/message_read")
        .add("act", act)
        .add("message_id", messageId)
        .asClass(HttpServiceData::class.java)
    , listener
)

/**
 * 互动消息 - 赞
 *
 * @param limit 条数
 * @param page 分页
 * */
fun messageLike(
    page: String, limit: String, listener: SubscribeListener<MessageLikeResponse>
): Disposable = subscribe(
    RxHttp.get("/api/message/like_messages")
        .add("page", page)
        .add("limit", limit)
        .asClass(MessageLikeResponse::class.java)
    , listener
)

/**
 * 互动消息 - 评论
 *
 * @param limit 条数
 * @param page 分页
 * */
fun messageComment(
    page: String, limit: String, listener: SubscribeListener<MessageCommentResponse>
): Disposable = subscribe(
    RxHttp.get("/api/message/comment_messages")
        .add("page", page)
        .add("limit", limit)
        .asClass(MessageCommentResponse::class.java)
    , listener
)

/**
 * 互动消息 - 回复
 *
 * @param limit 条数
 * @param page 分页
 * */
fun messageReply(
    page: String, limit: String, listener: SubscribeListener<MessageReplyResponse>
): Disposable = subscribe(
    RxHttp.get("/api/message/reply_messages")
        .add("page", page)
        .add("limit", limit)
        .asClass(MessageReplyResponse::class.java)
    , listener
)


/**
 * 聊天列表
 * */
fun messageChatIndex(
    listener: SubscribeListener<ChatIndexResponse>
): Disposable = subscribe(
    RxHttp.get("/api/chat/index")
        .asClass(ChatIndexResponse::class.java)
    , listener
)

/**
 * 聊天详情
 * */
fun messageChatList(
    userId:String, listener: SubscribeListener<ChatListResponse>
): Disposable = subscribe(
    RxHttp.get("/api/chat/message_list")
        .add("user_id", userId)
        .asClass(ChatListResponse::class.java)
    , listener
)